package com.qf.web.service.impl;

import com.qf.common.dto.product.CategoryDto;
import com.qf.common.utils.CopyBeanUtils;
import com.qf.web.common.api.product.CategoryApi;
import com.qf.web.entity.Banner;
import com.qf.web.entity.Navigation;
import com.qf.web.mapper.BannerMapper;
import com.qf.web.mapper.NavigationMapper;
import com.qf.web.service.HomeService;
import com.qf.web.vo.BannerVo;
import com.qf.web.vo.HomeVo;
import com.qf.web.vo.NavigationVo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author KING
 * @ClassName: com.qf.web.service.impl.HomeServiceImpl
 * @Description: 该类的功能描述
 * @date: 2021/11/10 21:08
 */
@Service
public class HomeServiceImpl implements HomeService {
    @Resource
    private BannerMapper bannerMapper;
    @Resource
    private NavigationMapper navigationMapper;
    @Resource
    private CategoryApi categoryApi;

    @Override
    public HomeVo getHeadData() {
        HomeVo homeVo = new HomeVo();
        /**
         * 获取轮播图信息
         */
        List<Banner> banners = bannerMapper.getBanners();
        List<BannerVo> bannerList = CopyBeanUtils.copyListProperties(banners, BannerVo::new);
        homeVo.setBannerList(bannerList);

        /**
         * 获取顶部导航信息
         */
        List<Navigation> navigations = navigationMapper.getNavigations();
        List<NavigationVo> navigationVos = CopyBeanUtils.copyListProperties(navigations, NavigationVo::new);
        homeVo.setNavigationList(navigationVos);

        /**
         * 调用商品模块的接口，得到商品分类信息
         */
        List<CategoryDto> categories = categoryApi.getCategories();
        homeVo.setCategoryList(categories);
        return homeVo;
    }
}
